package com.app.controller;

/*
  @author 阿伟
  @create 2020-11-23:14:53
  投诉/反馈Controller
*/

import com.app.condition.CompliantCondition;
import com.app.dao.CompliantDao;
import com.app.service.CompliantService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.common.entity.Code;
import com.common.entity.Compliant;
import com.common.entity.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api(tags = "投诉/反馈模块")
@RestController
@RequestMapping("/compliant")
public class CompliantController {

    @Autowired
    CompliantService compliantService;

    @Autowired
    CompliantDao compliantDao;

    @ApiOperation(value = "通过ID查询投诉/反馈的数据")
    @GetMapping("/one")
    public ResponseResult getCompliantById(
            @ApiParam(name = "compliantId",value = "投诉/反馈ID",required = true)
            @RequestParam("compliantId") String compliantId){
//        Compliant compliant = compliantService.getById(Integer.parseInt(compliantId));
        Compliant compliant = compliantDao.selectById(compliantId);
        return ResponseResult.success(Code.REQUEST_SUCCESS).Data("compliant",compliant);
    }

    @ApiOperation(value = "分页查询用户")
    @GetMapping("/page")
    public ResponseResult getCompliantByLimit(
            @ApiParam(name = "pageIndex",value = "当前页",required = true)
            @RequestParam("pageIndex") String pageIndex,
            @ApiParam(name = "pageSize",value = "页大小",required = true)
            @RequestParam("pageSize") String pageSize,
            @ApiParam(name = "compliantCondition",value = "查询的条件",required = false)
                    CompliantCondition compliantCondition){
        Long index = Long.parseLong(pageIndex);
        Long size = Long.parseLong(pageSize);
        //page对象
        Page<Compliant> page = new Page<>(index,size);
        compliantService.selectCompliantByLimit(page,compliantCondition);
        List<Compliant> Compliants = page.getRecords();
        return ResponseResult.success(Code.REQUEST_SUCCESS).Data("user",Compliants);
    }

    @ApiOperation(value = "添加投诉/反馈")
    @PostMapping("/insert")
    public ResponseResult insertCompliant(
            @ApiParam(name = "multipartFile",value = "图片",required = false)
            @RequestParam("multipartFile") MultipartFile multipartFile,
            @ApiParam(name = "phone",value = "手机号",required = true)
            @RequestParam("phone") String phone,
            @ApiParam(name = "comtype",value = "反馈类型",required = true)
            @RequestParam("comtype") String comtype,
            @ApiParam(name = "question",value = "问题",required = true)
            @RequestParam("question") String question){
        return compliantService.addCompliant(phone,comtype,question,multipartFile);
    }

    @ApiOperation(value = "查询所有的投诉/反馈")
    @GetMapping("/getallcompliant")
    public ResponseResult getAllCompliant(){

        return compliantService.getAllCompliant();
    }
}
